package com.chen.controller;

import com.chen.base.PageResponse;
import com.chen.base.ResponseResult;
import com.chen.dto.NursingLevelDto;
import com.chen.service.NursingLevelService;
import com.chen.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 护理等级管理
 */
@RestController
@RequestMapping("/nursingLevel")
public class NursingLevelController {
    @Resource
    private NursingLevelService nursingLevelService;

    /**
     * 查询所有护理等级信息
     * @return
     */
    @GetMapping("/listAll")
    public ResponseResult<List<NursingLevelVo>> listAll() {
        List<NursingLevelVo> nursingLevelDtos = nursingLevelService.listAll();
        return ResponseResult.success(nursingLevelDtos);
    }

    /**
     * 批量插入护理等级信息
     * @param nursingLevelDtos
     * @return
     */
    @PostMapping("/insertBatch")
    public ResponseResult insertBatch(
            @ApiParam(value = "护理等级数据列表", required = true)
            @RequestBody List<NursingLevelDto> nursingLevelDtos) {
        nursingLevelService.insertBatch(nursingLevelDtos);
        return ResponseResult.success();
    }

    /**
     * 插入护理等级信息
     * @param nursingLevel
     * @return
     */
    @PostMapping("/insert")
    public ResponseResult insert(
            @ApiParam(value = "护理等级数据", required = true)
            @RequestBody NursingLevelDto nursingLevel) {
        nursingLevelService.insert(nursingLevel);
        return ResponseResult.success();
    }

    /**
     * 更新护理等级信息
     * @param nursingLevel
     * @return
     */
    @PutMapping("/update")
    public ResponseResult update(
            @ApiParam(value = "护理等级数据", required = true)
            @RequestBody NursingLevelDto nursingLevel) {
        nursingLevelService.update(nursingLevel);
        return ResponseResult.success();
    }

    /**
     * 删除护理等级信息
     * @param id 护理等级ID
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseResult delete(@PathVariable("id") Long id) {
        nursingLevelService.delete(id);
        return ResponseResult.success();
    }

    /**
     * 根据ID查询护理等级信息
     * @param id 护理等级ID
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult<NursingLevelVo> findById(@PathVariable("id") Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return ResponseResult.success(nursingLevelVo);
    }

    /**
     * 分页查询护理等级信息
     * @param pageNum 页码
     * @param pageSize 每页大小
     * @param name 护理等级名称
     * @param status 护理等级状态
     * @return
     */
    @GetMapping("/listByPage")
    public ResponseResult<PageResponse<NursingLevelVo>> listByPage(
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize,
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "status", required = false) Integer status) {
        PageResponse<NursingLevelVo> nursingLevelVoPageResponse = nursingLevelService.listByPage(pageNum, pageSize, name, status);
        return ResponseResult.success(nursingLevelVoPageResponse);
    }

    /**
     * 启用/禁用护理等级
     * @param id 护理等级ID
     * @param status 状态，0：禁用，1：启用
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    public ResponseResult enableOrDisable(@PathVariable Long id, @PathVariable Integer status) {
        nursingLevelService.enableOrDisable(id, status);
        return ResponseResult.success();
    }
}
